import { createApp } from './app'
import { getDefaultConfig } from '../config/app_default.cfg'
import { WSS } from './shared/request/websocket'
import { Vite } from 'koagun'

(async () => {
  let config = getDefaultConfig()
  if (config.ENV === 'local') {
    // @ts-ignore
    config = (await import('../config/app_local.cfg')).getLocalConfig()
  }
  const app = await createApp(config)
  console.log(`${app.env.toUpperCase()} - Successfully running in http://127.0.0.1:${app.config.LISTEN_PORT}`)
  app.run()
  WSS.createWebSocketServer(app)
})()
  .catch(e => {
    console.error(e)
    process.exit(1)
  })
